<?php

/**
 * Operaciones form.
 *
 * @package    tercermilenio
 * @subpackage form
 * @author     Your name here
 */
class OperacionesForm extends BaseOperacionesForm {

    public function configure() {
        $this->getWidget('op_usuario')->setAttribute('readonly', 'readonly');
        if (!$this->isNew()) {
            $this->widgetSchema['op_monto']->setAttribute('disabled', true);
            $this->widgetSchema['op_motivo']->setAttribute('disabled', true);
            $this->widgetSchema['op_tipo']->setAttribute('disabled', true);
            $this->widgetSchema['op_usuario']->setAttribute('disabled', true);
        }
    }

    public function setup() {

        parent::setup();

        $this->setWidgets(array(
            'op_id' => new sfWidgetFormInputHidden(),
            'op_monto' => new sfWidgetFormInput(),
            'op_motivo' => new sfWidgetFormTextarea(),
            'op_tipo' => new sfWidgetFormPropelChoice(array('model' => 'TipoOperaciones', 'add_empty' => 'Seleccione un tipo')),
            'op_usuario' => new sfWidgetFormPropelChoice(array('model' => 'sfGuardUser', 'add_empty' => false)),
        ));

        $this->setValidators(array(
            'op_id' => new sfValidatorPropelChoice(array('model' => 'Operaciones', 'column' => 'op_id', 'required' => false)),
            'op_monto' => new sfValidatorNumber(array('required' => true)),
            'op_motivo' => new sfValidatorString(array('max_length' => 200, 'required' => true)),
            'op_tipo' => new sfValidatorPropelChoice(array('model' => 'TipoOperaciones', 'column' => 'tip_op_tipo', 'required' => true)),
            'op_usuario' => new sfValidatorPropelChoice(array('model' => 'sfGuardUser', 'column' => 'id', 'required' => false)),
        ));

        $this->widgetSchema->setNameFormat('operaciones[%s]');

        $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
    }

}
